<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  <meta name="referrer" content="origin">
  <meta name="viewport" content="width=device-width, viewport-fit=cover, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
  <meta name="Cache-Control" content="no-cache, no-store, must-revalidate">
  <title>支付结果 - 智能门禁运营平台</title>
  <script type="text/javascript" charset="UTF-8" src="https://wx.gtimg.com/pay_h5/goldplan/js/jgoldplan-1.0.0.js"></script>
  <style>
    body {
      margin: 0;
      padding: 0;
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
      background-color: #f7f8fa;
    }
    .container {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      min-height: 100vh;
      padding: 20px;
      box-sizing: border-box;
    }
    .loading {
      text-align: center;
    }
    .loading-text {
      margin-top: 15px;
      color: #666;
      font-size: 16px;
    }
    .spinner {
      width: 40px;
      height: 40px;
      border: 4px solid rgba(7, 193, 96, 0.2);
      border-radius: 50%;
      border-top-color: #07c160;
      animation: spin 1s ease-in-out infinite;
      margin: 0 auto;
    }
    @keyframes spin {
      to { transform: rotate(360deg); }
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="loading">
      <div class="spinner"></div>
      <div class="loading-text">正在加载支付结果...</div>
    </div>
  </div>

  <script>
    document.addEventListener('DOMContentLoaded', function() {
      // 解析URL参数
      function getQueryParams() {
        const params = {};
        const search = window.location.search.substring(1);
        if (!search) return params;
        
        const pairs = search.split('&');
        for (let i = 0; i < pairs.length; i++) {
          const pair = pairs[i].split('=');
          params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
        }
        return params;
      }

      // 初始化点金计划
      function initGoldPlan() {
        // 通知微信点金计划页面已准备就绪
        const mchData = {
          action: 'onIframeReady',
          displayStyle: 'SHOW_CUSTOM_PAGE',
          height: 600
        };
        const postData = JSON.stringify(mchData);
        parent.postMessage(postData, '*');
        
        // 监听来自微信的消息
        window.addEventListener('message', function(event) {
          try {
            const data = JSON.parse(event.data);
            if (data && data.action === 'onReceivedData') {
              // 获取支付信息
              const paymentInfo = data.paymentInfo || {};
              const outTradeNo = paymentInfo.outTradeNo || '';
              const amount = paymentInfo.amount || '0.00';
              
              // 跳转到应用内的商家小票页面
              redirectToAppPage(outTradeNo, amount);
            }
          } catch (e) {
            console.error('解析点金计划消息失败', e);
            // 出错时也跳转到应用页面
            redirectToAppPage();
          }
        });
      }

      // 跳转到应用内的商家小票页面
      function redirectToAppPage(outTradeNo = '', amount = '') {
        const params = getQueryParams();
        const orderNo = outTradeNo || params.orderNo || '';
        const orderAmount = amount || params.amount || '';
        const orderInfo = params.orderInfo || '门禁升级缴费';
        const orderId = params.orderId || '';
        
        // 构建跳转URL
        let redirectUrl = '/pages/common/goldplan/index';
        const queryParams = [];
        
        if (orderNo) queryParams.push(`orderNo=${encodeURIComponent(orderNo)}`);
        if (orderAmount) queryParams.push(`amount=${encodeURIComponent(orderAmount)}`);
        if (orderInfo) queryParams.push(`orderInfo=${encodeURIComponent(orderInfo)}`);
        if (orderId) queryParams.push(`orderId=${encodeURIComponent(orderId)}`);
        
        if (queryParams.length > 0) {
          redirectUrl += '?' + queryParams.join('&');
        }
        
        // 延迟一秒后跳转，确保点金计划初始化完成
        setTimeout(function() {
          window.location.href = redirectUrl;
        }, 1000);
      }

      // 初始化
      initGoldPlan();
    });
  </script>
</body>
</html> 